package com.example.mapper;

import com.example.model.WxbOrder;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface OrderMapper extends Mapper<WxbOrder> {

    @Select(value = "select o.oid,o.order_id,o.good_id,o.buy_num,o.buyer_name,o.buyer_phone,o.province,o.city,o.area,o.address,o.order_type,o.order_time,o.pay_type,o.state,o.alipay_state,k.sku_name,k.sku_price,k.sku_pmoney,g.customer_id,g.good_name from wxb_order o left join wxb_good_sku k on k.good_id = o.good_id left\n" +
            "    join wxb_good g on k.good_id = g.good_id where g.customer_id = #{customerId}")
    List<WxbOrder> findByCustomerId(String cusyomerId);

    @Update(value = "update wxb_order set state = #{state} where oid = #{oid}")
    public void updateState(@Param("state") int state,
                            @Param("oid") String oid);

    @Delete(value = "delete from wxb_order where alipay_state = '0' and oid = #{oid}")
    void deleteById(Long oid);

    @Update(value = "update wxb_order set alipay_state ='1' where order_id = #{orderId}")
    void updateAlipayState(String orderId);

}
